/*
 * @Descripttion: 
 * @version: 
 * @Author: Miller Zhou
 * @Date: 2021-02-18 13:51:27
 * @LastEditors: Miller Zhou
 * @LastEditTime: 2021-02-19 21:29:24
 */
#ifndef __ZIIC_H__
#define __ZIIC_H__

#include "nativeInterface.h"
#include <stdint.h>
#include "ZcommonDrv.h"

/*Select the mcus*/
#ifdef mcu_stm32f4_hal
#include "stm32f4xx_hal.h"
/*IO direction setting*/
// #define SDA_IN()                         \
//     {                                    \
//         GPIOC->CRH &= 0xFFFF0FFF;        \
//         GPIOC->CRH |= (uint32_t)8 << 12; \
//     } //PC12 input model
// #define SDA_OUT()                        \
//     {                                    \
//         GPIOC->CRH &= 0xFFFF0FFF;        \
//         GPIOC->CRH |= (uint32_t)3 << 12; \
//     } //PC12 output model
#endif

#ifdef mcu_stm32f1_hal
#include "stm32f1xx_hal.h"
/*IO direction setting*/
#define SDA_IN()                         \
    {                                    \
        GPIOC->CRH &= 0xFFFF0FFF;        \
        GPIOC->CRH |= (uint32_t)8 << 12; \
    } //PC12 input model
#define SDA_OUT()                        \
    {                                    \
        GPIOC->CRH &= 0xFFFF0FFF;        \
        GPIOC->CRH |= (uint32_t)3 << 12; \
    } //PC12 output model
#endif

/*C Includes*/
#include "main.h"

#ifdef __cplusplus
extern "C"
{
#endif

/*C Defines*/
#define SCL SCL_GPIO_Port, SCL_Pin
#define SDA SDA_GPIO_Port, SDA_Pin

/*****************************************************************
                      Function declaration
*****************************************************************/
void SCL_L(void);
void SCL_H(void);
void SDA_H(void);
void SDA_L(void);

void IIC_Init(void);
void IIC_Start(void);
void IIC_Stop(void);
void IIC_Send_Byte(uint8_t txd);
uint8_t IIC_Read_Byte(unsigned char ack);
uint8_t IIC_Wait_Ack(void);
void IIC_Ack(void);
void IIC_NAck(void);
void IIC_Write_One_Byte(uint8_t daddr, uint8_t addr, uint8_t data);
uint8_t IIC_Read_One_Byte(uint8_t daddr, uint8_t addr);

#ifdef __cplusplus
}
#endif

#endif